#include "agvsetdialog.h"
#include "ui_agvsetdialog.h"
#include <qmessagebox.h>
#include "../CommunicateDelegate/communicatenormaldelegate.h"

AgvSetDialog::AgvSetDialog(CommunicateNormalDelegate *communicateNormalIn, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AgvSetDialog)
{
    communicateNormal=communicateNormalIn;
    ui->setupUi(this);
}

AgvSetDialog::~AgvSetDialog()
{
    delete ui;
}

void AgvSetDialog::showWindowSlot()
{
    show();
    on_tabWidget_tabBarClicked(ui->tabWidget->currentIndex());

}

void AgvSetDialog::on_pushButton_setVehicleBorderOffset_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }
    int returnFlag;
    double front=ui->lineEdit_vehicleBorder_front->text().toDouble();
    double back=ui->lineEdit_vehicleBorder_back->text().toDouble();
    double left=ui->lineEdit_vehicleBorder_left->text().toDouble();
    double right=ui->lineEdit_vehicleBorder_right->text().toDouble();
    communicateNormal->setVehicleBorderOffset_rect(front,back,left,right,returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "提示", "边框偏移设置成功(不写入文件),立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "设置失败！", QMessageBox::Yes );
    }

}

void AgvSetDialog::on_pushButton_reset_vehicle_calibrate_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }
    int returnFlag;
    double x=ui->lineEdit_vehicle_calibrate_x->text().toDouble();
    double y=ui->lineEdit_vehicle_calibrate_y->text().toDouble();
    double r=ui->lineEdit_vehicle_calibrate_r->text().toDouble()/180.0*M_PI;
    communicateNormal->calibrateVehicle(x,y,r,returnFlag);
    if(1==returnFlag)
    {
       QMessageBox::information(NULL, "information", "校准成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "失败", QMessageBox::Yes );
    }


}

bool AgvSetDialog::isAuthorityOk()
{
    QString code=ui->lineEdit_vehicle_calibrate_authority_code->text();
    if(code=="123456")
    {
        ui->lineEdit_vehicle_calibrate_authority_code->setText("");
        return true;
    }
    else
    {
        QMessageBox::information(NULL, "information", "授权码不对，请重新输入", QMessageBox::Yes );
//        ui->lineEdit_vehicle_calibrate_authority_code->setText("请重新输入授权码");
        return false;
    }
    return false;
}

void AgvSetDialog::readBarrierSet()
{

    CollisionPara infoOut;
    if(1==communicateNormal->getSafeCollisionInfo(ui->comboBox_barrierMode->currentIndex(),infoOut))
    {
        ui->lineEdit_barrierSlowDownDistance_x->setText(QString::number(infoOut.barrierSlowDownDistance_x));
        ui->lineEdit_barrierSlowDownDistance_y->setText(QString::number(infoOut.barrierSlowDownDistance_y));
        ui->lineEdit_barrierStopDistance->setText(QString::number(infoOut.barrierStopDistance_x));
        ui->lineEdit_barrierStopDistance_y->setText(QString::number(infoOut.barrierStopDistance_y));
        ui->lineEdit_pieExtendedDistance->setText(QString::number(infoOut.pieExtendedDistance));
        if(infoOut.stepSafetyRatioList.size()>=7)
        {
            ui->lineEdit_stepVel1->setText(QString::number(infoOut.stepSafetyRatioList[0].velocity));
            ui->lineEdit_stepDistance1->setText(QString::number(infoOut.stepSafetyRatioList[0].newDistance));
            ui->lineEdit_stepRatio1->setText(QString::number(infoOut.stepSafetyRatioList[0].newSlowDownRatio));
            ui->lineEdit_stepRatio_newTime1->setText(QString::number(infoOut.stepSafetyRatioList[0].newSlowTime));


            ui->lineEdit_stepVel2->setText(QString::number(infoOut.stepSafetyRatioList[1].velocity));
            ui->lineEdit_stepDistance2->setText(QString::number(infoOut.stepSafetyRatioList[1].newDistance));
            ui->lineEdit_stepRatio2->setText(QString::number(infoOut.stepSafetyRatioList[1].newSlowDownRatio));
            ui->lineEdit_stepRatio_newTime2->setText(QString::number(infoOut.stepSafetyRatioList[1].newSlowTime));

            ui->lineEdit_stepVel3->setText(QString::number(infoOut.stepSafetyRatioList[2].velocity));
            ui->lineEdit_stepDistance3->setText(QString::number(infoOut.stepSafetyRatioList[2].newDistance));
            ui->lineEdit_stepRatio3->setText(QString::number(infoOut.stepSafetyRatioList[2].newSlowDownRatio));
            ui->lineEdit_stepRatio_newTime3->setText(QString::number(infoOut.stepSafetyRatioList[2].newSlowTime));

            ui->lineEdit_stepVel4->setText(QString::number(infoOut.stepSafetyRatioList[3].velocity));
            ui->lineEdit_stepDistance4->setText(QString::number(infoOut.stepSafetyRatioList[3].newDistance));
            ui->lineEdit_stepRatio4->setText(QString::number(infoOut.stepSafetyRatioList[3].newSlowDownRatio));
            ui->lineEdit_stepRatio_newTime4->setText(QString::number(infoOut.stepSafetyRatioList[3].newSlowTime));

            ui->lineEdit_stepVel5->setText(QString::number(infoOut.stepSafetyRatioList[4].velocity));
            ui->lineEdit_stepDistance5->setText(QString::number(infoOut.stepSafetyRatioList[4].newDistance));
            ui->lineEdit_stepRatio5->setText(QString::number(infoOut.stepSafetyRatioList[4].newSlowDownRatio));
            ui->lineEdit_stepRatio_newTime5->setText(QString::number(infoOut.stepSafetyRatioList[4].newSlowTime));

            ui->lineEdit_stepVel6->setText(QString::number(infoOut.stepSafetyRatioList[5].velocity));
            ui->lineEdit_stepDistance6->setText(QString::number(infoOut.stepSafetyRatioList[5].newDistance));
            ui->lineEdit_stepRatio6->setText(QString::number(infoOut.stepSafetyRatioList[5].newSlowDownRatio));
            ui->lineEdit_stepRatio_newTime6->setText(QString::number(infoOut.stepSafetyRatioList[5].newSlowTime));

            ui->lineEdit_stepVel7->setText(QString::number(infoOut.stepSafetyRatioList[6].velocity));
            ui->lineEdit_stepDistance7->setText(QString::number(infoOut.stepSafetyRatioList[6].newDistance));
            ui->lineEdit_stepRatio7->setText(QString::number(infoOut.stepSafetyRatioList[6].newSlowDownRatio));
            ui->lineEdit_stepRatio_newTime7->setText(QString::number(infoOut.stepSafetyRatioList[6].newSlowTime));
        }
        QMessageBox::information(NULL, "提示", "获取避障参数成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "获取避障参数失败", QMessageBox::Yes );
    }

}

void AgvSetDialog::readAgvBorderSet()
{
    VehicleKinematicDimension kineDmension;
    communicateNormal->getVehicleKinematicDimension(kineDmension);

    VehicleBorderInfo tmpRect;
    if(1==communicateNormal->getAgvBorderInfo(tmpRect))
    {
        ui->lineEdit_vehicleBorder_x1->setText(QString::number(tmpRect.x[0]));
        ui->lineEdit_vehicleBorder_x2->setText(QString::number(tmpRect.x[1]));
        ui->lineEdit_vehicleBorder_x3->setText(QString::number(tmpRect.x[2]));
        ui->lineEdit_vehicleBorder_x4->setText(QString::number(tmpRect.x[3]));

        ui->lineEdit_vehicleBorder_y1->setText(QString::number(tmpRect.y[0]));
        ui->lineEdit_vehicleBorder_y2->setText(QString::number(tmpRect.y[1]));
        ui->lineEdit_vehicleBorder_y3->setText(QString::number(tmpRect.y[2]));
        ui->lineEdit_vehicleBorder_y4->setText(QString::number(tmpRect.y[3]));

        ui->lineEdit_vehicleBorder_front->setText(QString::number(tmpRect.offset_front));
        ui->lineEdit_vehicleBorder_back->setText(QString::number(tmpRect.offset_back));
        ui->lineEdit_vehicleBorder_left->setText(QString::number(tmpRect.offset_left));
        ui->lineEdit_vehicleBorder_right->setText(QString::number(tmpRect.offset_right));

        ui->lineEdit_vehicle_diameter->setText(QString::number(kineDmension.diameter));
        ui->lineEdit_vehicle_wa->setText(QString::number(kineDmension.wa));
        ui->lineEdit_vehicle_wb->setText(QString::number(kineDmension.wb));
        qDebug()<<"diameter"<<kineDmension.diameter<<"wa"<<kineDmension.wa<<"wb"<<kineDmension.wb;

        QMessageBox::information(NULL, "提示", "获取车尺寸参数成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "获取车尺寸参数失败", QMessageBox::Yes );
    }



}

void AgvSetDialog::readLaserScanSet()
{
    LaserScanParameterHmi infoOut;
    if(1==communicateNormal->getLaserScanParameter(0,infoOut))
    {
        ui->lineEdit_laserScan_x->setText(QString::number(infoOut.position[0]));
        ui->lineEdit_laserScan_y->setText(QString::number(infoOut.position[1]));
        ui->lineEdit_laserScan_z->setText(QString::number(infoOut.position[2]));
        ui->lineEdit_laserScan_w->setText(QString::number(infoOut.position[3]));
        ui->lineEdit_laserScan_p->setText(QString::number(infoOut.position[4]));
        ui->lineEdit_laserScan_r->setText(QString::number(infoOut.position[5]));

        ui->lineEdit_laserScan_minAngle->setText(QString::number(infoOut.minAngle));
        ui->lineEdit_laserScan_maxAngle->setText(QString::number(infoOut.maxAngle));

        QMessageBox::information(NULL, "提示", "获取前激光扫描仪参数成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "获取前激光扫描仪失败", QMessageBox::Yes );
    }
}

void AgvSetDialog::readMotionSet()
{
    VehicleTrajectoryControlParameter trajInfo;
    communicateNormal->getVehicleTrajectoryControlParameter(trajInfo);
    VehicleJogControlParameter jogInfo;
    if(1==communicateNormal->getVehicleJogControlParameter(jogInfo))
    {
        ui->lineEdit_vehicle_jogVel_x->setText(QString::number(jogInfo.maxVel_x));
        ui->lineEdit_vehicle_jogVel_y->setText(QString::number(jogInfo.maxVel_y));
        ui->lineEdit_vehicle_jogVel_r->setText(QString::number(jogInfo.maxVel_r));

        ui->lineEdit_vehicle_traj_maxVelLine->setText(QString::number(trajInfo.maxVel_line));
        ui->lineEdit_vehicle_traj_maxAccLine->setText(QString::number(trajInfo.maxAcc_line));
        ui->lineEdit_vehicle_traj_maxVelRotate->setText(QString::number(trajInfo.maxVel_rotate));
        ui->lineEdit_vehicle_traj_maxAccRotate->setText(QString::number(trajInfo.maxAcc_rotate));

        QMessageBox::information(NULL, "提示", "获取运动参数成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "获取运动参数失败", QMessageBox::Yes );
    }
}

void AgvSetDialog::readSheftSet()
{
    BorderRectInfo tmpRect;
    if(1==communicateNormal->getAgvSheftInfo(ui->comboBox_borderId->currentIndex(),tmpRect))
    {
        ui->lineEdit_vehicleShelf_x1->setText(QString::number(tmpRect.x[0]));
        ui->lineEdit_vehicleShelf_x2->setText(QString::number(tmpRect.x[1]));
        ui->lineEdit_vehicleShelf_x3->setText(QString::number(tmpRect.x[2]));
        ui->lineEdit_vehicleShelf_x4->setText(QString::number(tmpRect.x[3]));

        ui->lineEdit_vehicleShelf_y1->setText(QString::number(tmpRect.y[0]));
        ui->lineEdit_vehicleShelf_y2->setText(QString::number(tmpRect.y[1]));
        ui->lineEdit_vehicleShelf_y3->setText(QString::number(tmpRect.y[2]));
        ui->lineEdit_vehicleShelf_y4->setText(QString::number(tmpRect.y[3]));
        QMessageBox::information(NULL, "提示", "获取货架参数成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "获取货架参数失败", QMessageBox::Yes );
    }
}

void AgvSetDialog::readAgvPositionCalibrateSet()
{
    VehiclePosition infoOut;
    if(1==communicateNormal->getVehiclePositionCalibrateInfo(infoOut))
    {
        ui->lineEdit_vehicle_calibrate_x->setText(QString::number(infoOut.x));
        ui->lineEdit_vehicle_calibrate_y->setText(QString::number(infoOut.y));
        ui->lineEdit_vehicle_calibrate_r->setText(QString::number(180.0*infoOut.rotate/M_PI));

        QMessageBox::information(NULL, "提示", "获取位置校准参数成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "获取位置校准参数失败", QMessageBox::Yes );
    }
}

void AgvSetDialog::readLiftSet()
{
    LiftMechanismConfig infoIn;
    if(1==communicateNormal->getLiftMechanismConfig(infoIn))
    {
        //block1
        ui->comboBox_liftType->setCurrentIndex(infoIn.blockType);
        ui->lineEdit_liftAxisId->setText(QString::number(infoIn.heavyLift_axisId+1));
        ui->lineEdit_liftDi1->setText(QString::number(infoIn.heavyTopSensor_index+1));
        ui->lineEdit_liftDi2->setText(QString::number(infoIn.heavyButtomSensor_index+1));
        ui->lineEdit_liftDiMiddle->setText(QString::number(infoIn.heavyMiddleSensor_index+1));
        ui->lineEdit_liftDo1->setText(QString::number(infoIn.heavyMotorPositive_index+1));
        ui->lineEdit_liftDo2->setText(QString::number(infoIn.heavyMotorReverse_index+1));
        //block2
        ui->comboBox_liftType_2->setCurrentIndex(infoIn.blockBType);
        ui->lineEdit_liftAxisId_2->setText(QString::number(infoIn.heavyLiftB_axisId+1));
        ui->lineEdit_liftDi1_2->setText(QString::number(infoIn.heavyTopSensorB_index+1));
        ui->lineEdit_liftDi2_2->setText(QString::number(infoIn.heavyButtomSensorB_index+1));
        ui->lineEdit_liftDiMiddle_2->setText(QString::number(infoIn.heavyMiddleSensorB_index+1));
        ui->lineEdit_liftDo1_2->setText(QString::number(infoIn.heavyMotorPositiveB_index+1));
        ui->lineEdit_liftDo2_2->setText(QString::number(infoIn.heavyMotorReverseB_index+1));
        //common
        ui->lineEdit_liftAxisSpeed->setText(QString::number(infoIn.heavyLiftSpeed));
        ui->comboBox_liftIsUseSheftBarrier->setCurrentIndex(infoIn.isSetSheftRegion);
        ui->comboBox_liftIsUseWatchDi->setCurrentIndex(infoIn.isWatchButtonDi);
        ui->lineEdit_liftJogDi1->setText(QString::number(infoIn.upButtonDiIndex+1));
        ui->lineEdit_liftJogDi2->setText(QString::number(infoIn.downButtonDiIndex+1));
        ui->lineEdit_liftJogSpeed->setText(QString::number(infoIn.liftManualSpeed));

        ui->lineEdit_liftTimeOut->setText(QString::number(infoIn.liftTimeOut));
        ui->comboBox_liftmotorExchangeDirection->setCurrentIndex(infoIn.liftDirectionExchange);

        QMessageBox::information(NULL, "提示", "获取顶升机构参数成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "获取顶升机构参数失败", QMessageBox::Yes );
    }
}

void AgvSetDialog::readRollerSet()
{
    RollerMechanismConfig infoIn;
    if(1==communicateNormal->getRollerMechanismConfig(infoIn))
    {
        ui->comboBox_rollerType->setCurrentIndex(infoIn.rollerMechanicalType);
        ui->lineEdit_rollerblockWaitTime->setText(QString::number(infoIn.blockWaitTime));
        ui->lineEdit_rollerdownLoadDelayTime->setText(QString::number(infoIn.leaveDelayTime));
        ui->lineEdit_rollerArriveDelayTime->setText(QString::number(infoIn.arriveDelayTime));
        //roller
        ui->lineEdit_RollerleftArrive->setText(QString::number(infoIn.commonLeftArriveSensor_index+1));
        ui->lineEdit_RollerRightArrive->setText(QString::number(infoIn.commonRightArriveSensor_index+1));
        ui->lineEdit_RollerleftLeave->setText(QString::number(infoIn.commonLeftLeaveSensor_index+1));
        ui->lineEdit_RollerrightLeave->setText(QString::number(infoIn.commonRightLeaveSensor_index+1));
        ui->lineEdit_RollercommonDo1->setText(QString::number(infoIn.commonMotorPositiveDo_index+1));
        ui->lineEdit_RollercommonDo2->setText(QString::number(infoIn.commonMotorReverseDo_index+1));
        ui->lineEdit_rollerTimeOut->setText(QString::number(infoIn.rollerTimeOut));
        ui->comboBox_rollermotorControlType->setCurrentIndex(infoIn.rollerMotorType);
        ui->comboBox_rollermotorExchangeDirection->setCurrentIndex(infoIn.rollerDirectionExchange);

        //left block1
        ui->comboBox_RollerLeftblockType->setCurrentIndex(infoIn.leftBlockType);
        ui->lineEdit_RollerleftBlockDi1->setText(QString::number(infoIn.leftTopSensor_index+1));
        ui->lineEdit_RollerleftBlockDi2->setText(QString::number(infoIn.leftButtomSensor_index+1));
        ui->lineEdit_RollerleftBlockDo1->setText(QString::number(infoIn.leftBlockDo1_index+1));
        ui->lineEdit_RollerleftBlockDo2->setText(QString::number(infoIn.leftBlockDo2_index+1));

        //right block1
        ui->comboBox_RollerRightblockType->setCurrentIndex(infoIn.rightBlockType);
        ui->lineEdit_RollerRightBlockDi1->setText(QString::number(infoIn.rightTopSensor_index+1));
        ui->lineEdit_RollerRightBlockDi2->setText(QString::number(infoIn.rightButtomSensor_index+1));
        ui->lineEdit_RollerRightBlockDo1->setText(QString::number(infoIn.rightBlockDo1_index+1));
        ui->lineEdit_RollerRightBlockDo2->setText(QString::number(infoIn.rightBlockDo2_index+1));

        //left block2
        ui->comboBox_RollerLeftblockType_2->setCurrentIndex(infoIn.leftBlockBType);
        ui->lineEdit_RollerleftBlockDi1_2->setText(QString::number(infoIn.leftTopSensorB_index+1));
        ui->lineEdit_RollerleftBlockDi2_2->setText(QString::number(infoIn.leftButtomSensorB_index+1));
        ui->lineEdit_RollerleftBlockDo1_2->setText(QString::number(infoIn.leftBlockDo1B_index+1));
        ui->lineEdit_RollerleftBlockDo2_2->setText(QString::number(infoIn.leftBlockDo2B_index+1));

        //right block2
        ui->comboBox_RollerRightblockType_2->setCurrentIndex(infoIn.rightBlockBType);
        ui->lineEdit_RollerRightBlockDi1_2->setText(QString::number(infoIn.rightTopSensorB_index+1));
        ui->lineEdit_RollerRightBlockDi2_2->setText(QString::number(infoIn.rightButtomSensorB_index+1));
        ui->lineEdit_RollerRightBlockDo1_2->setText(QString::number(infoIn.rightBlockDo1B_index+1));
        ui->lineEdit_RollerRightBlockDo2_2->setText(QString::number(infoIn.rightBlockDo2B_index+1));


        QMessageBox::information(NULL, "提示", "获取滚筒机构参数成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "获取滚筒机构参数失败", QMessageBox::Yes );
    }
}

void AgvSetDialog::readAmclConfig()
{
    AmclDebugPara paraOut;
    if(1==communicateNormal->getAmclPara(paraOut))
    {
        ui->lineEdit_calculateTimesForLaser->setText(QString::number(paraOut.calculateTimesForLaser));
        ui->lineEdit_laser_max_beams->setText(QString::number(paraOut.laser_max_beams));
        ui->lineEdit_min_particles->setText(QString::number(paraOut.min_particles));
        ui->lineEdit_max_particles->setText(QString::number(paraOut.max_particles));
        ui->lineEdit_update_min_d->setText(QString::number(paraOut.update_min_d));
        ui->lineEdit_update_min_a->setText(QString::number(paraOut.update_min_a));
        ui->lineEdit_odom_alpha1->setText(QString::number(paraOut.odom_alpha1));
        ui->lineEdit_odom_alpha2->setText(QString::number(paraOut.odom_alpha2));
        ui->lineEdit_odom_alpha3->setText(QString::number(paraOut.odom_alpha3));
        ui->lineEdit_odom_alpha4->setText(QString::number(paraOut.odom_alpha4));
        ui->lineEdit_odom_alpha5->setText(QString::number(paraOut.odom_alpha5));
        ui->lineEdit_badMatchScore->setText(QString::number(paraOut.badMatchScore));
        ui->lineEdit_goodMatchScore->setText(QString::number(paraOut.goodMatchScore));
        ui->lineEdit_newOdom_alpha_badMatchScore->setText(QString::number(paraOut.newOdom_alpha_badMatchScore));
        ui->lineEdit_recovery_alpha_slow->setText(QString::number(paraOut.recovery_alpha_slow));
        ui->lineEdit_recovery_alpha_fast->setText(QString::number(paraOut.recovery_alpha_fast));
        ui->lineEdit_resample_interval->setText(QString::number(paraOut.resample_interval));
        ui->lineEdit_odomOffsetFilterCount_amcl->setText(QString::number(paraOut.odomOffsetFilterCount));
        ui->lineEdit_isCorrectByReflect->setText(QString::number(paraOut.isCorrectByReflect));
        ui->lineEdit_correctFilterCount_amcl->setText(QString::number(paraOut.correctFilterCount));
        ui->lineEdit_correctAllowMaxDistanceOffset_amcl->setText(QString::number(paraOut.correctAllowMaxDistanceOffset));
        ui->lineEdit_correctAllowMaxAngleOffset_amcl->setText(QString::number(paraOut.correctAllowMaxAngleOffset));
        ui->lineEdit_qualifyReflectMinCertaintyScore->setText(QString::number(paraOut.qualifyReflectMinCertaintyScore));


        QMessageBox::information(NULL, "提示", "获取amcl参数成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "获取amcl参数失败", QMessageBox::Yes );
    }
}

void AgvSetDialog::readVehicleMotionCalibrate()
{
    VehicleMovingCaligrateInfo paraOut;
    if(1==communicateNormal->getVehicleMovingCaligrateInfo(paraOut))
    {
        ui->lineEdit_wheelCoee->setText(QString::number(paraOut.correctionFactor_wheelDiameter));
        ui->lineEdit_DistanceCoee->setText(QString::number(paraOut.correctionFactor_wheelDistance));
        ui->lineEdit_DistanceCoee_height->setText(QString::number(paraOut.correctionFactor_wheelDistance_height));

        QMessageBox::information(NULL, "提示", "获取运动校准参数成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "获取运动校准参数失败", QMessageBox::Yes );
    }

}

void AgvSetDialog::readReflectConfigInfo()
{
    ReflectCommonDetectPara paraOut;

    if(1==communicateNormal->getReflectCalculateCommonParameter(paraOut))
    {
        ui->lineEdit_allowMinMarkDistance->setText(QString::number(paraOut.allowMinMarkDistance));
        ui->lineEdit_minimumReferencePointCount->setText(QString::number(paraOut.minimumReferencePointCount));
        ui->lineEdit_maxmumReferencePointCount->setText(QString::number(paraOut.maxmumReferencePointCount));
        ui->lineEdit_maxMatchLineDistanceOffset->setText(QString::number(paraOut.maxMatchLineDistanceOffset));
        ui->lineEdit_initial_AgvPositionOffset->setText(QString::number(paraOut.initial_AgvPositionOffset));
        ui->lineEdit_initial_AgvAngleOffset->setText(QString::number(paraOut.initial_AgvAngleOffset));
        ui->lineEdit_mached_AgvPositionOffset->setText(QString::number(paraOut.mached_AgvPositionOffset));
        ui->lineEdit_mached_AgvAngleOffset->setText(QString::number(paraOut.mached_AgvAngleOffset));
        ui->lineEdit_odomErrorRatio_position->setText(QString::number(paraOut.odomErrorRatio_position));
        ui->lineEdit_odomErrorRatio_angle->setText(QString::number(paraOut.odomErrorRatio_angle));
        ui->lineEdit_laserIntensityLoseRatio->setText(QString::number(paraOut.laserIntensityLoseRatio));
        ui->lineEdit_matchColumnMarkDiameterTolorenceRatio->setText(QString::number(paraOut.matchColumnMarkDiameterTolorenceRatio));
        ui->lineEdit_matchPlaneMarkMinWidth->setText(QString::number(paraOut.matchPlaneMarkMinWidth));
        ui->lineEdit_matchPlaneMarkMaxWidth->setText(QString::number(paraOut.matchPlaneMarkMaxWidth));
        ui->lineEdit_odomOffsetFilterCount->setText(QString::number(paraOut.odomOffsetFilterCount));
        ui->lineEdit_minCorssAngle->setText(QString::number(paraOut.minCorssAngle));
        ui->lineEdit_idealRadius->setText(QString::number(paraOut.idealRadius));
        ui->lineEdit_idealMatchNum->setText(QString::number(paraOut.idealMatchNum));

        ui->lineEdit_isCorrectByAmcl->setText(QString::number(paraOut.isCorrectByAmcl));
        ui->lineEdit_qualifyAmclMinCertaintyScore->setText(QString::number(paraOut.qualifyAmclMinCertaintyScore));
        ui->lineEdit_correctFilterCount_reflect->setText(QString::number(paraOut.correctFilterCount));
        ui->lineEdit_correctAllowMaxDistanceOffset_reflect->setText(QString::number(paraOut.correctAllowMaxDistanceOffset));
        ui->lineEdit_correctAllowMaxAngleOffset_reflect->setText(QString::number(paraOut.correctAllowMaxAngleOffset));
        ui->lineEdit_correctOdomErrorDistanceThreshold->setText(QString::number(paraOut.correctOdomErrorDistanceThreshold));
        ui->lineEdit_correctOdomErrorAngleThreshold->setText(QString::number(paraOut.correctOdomErrorAngleThreshold));


        QMessageBox::information(NULL, "提示", "获取反光计算参数成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "获取反光计算参数失败", QMessageBox::Yes );
    }
}

void AgvSetDialog::readReflectFilterInfo()
{
    LaserFilterParameter paraOut;

    if(1==communicateNormal->getReflectLaserFilterParameter(ui->comboBox_reflectFilterIndex->currentIndex(),paraOut))
    {
        ui->lineEdit_minumIntensity_filter->setText(QString::number(paraOut.minumIntensity));
        ui->lineEdit_minLaserRange_filter->setText(QString::number(paraOut.minLaserRange));
        ui->lineEdit_maxLaserRange_filter->setText(QString::number(paraOut.maxLaserRange));
        ui->lineEdit_minAngle_filter->setText(QString::number(paraOut.minAngle));
        ui->lineEdit_maxAngle_filter->setText(QString::number(paraOut.maxAngle));
        ui->lineEdit_region_front_filter->setText(QString::number(paraOut.region_front));
        ui->lineEdit_region_back_filter->setText(QString::number(paraOut.region_back));
        ui->lineEdit_region_left_filter->setText(QString::number(paraOut.region_left));
        ui->lineEdit_region_right_filter->setText(QString::number(paraOut.region_right));

        QMessageBox::information(NULL, "提示", "获取反光激光过滤参数成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "获取反光激光过滤参数失败", QMessageBox::Yes );
    }
}

void AgvSetDialog::readBatteryPeakInfo()
{
    BatteryPeakConfig paraOut;

    if(1==communicateNormal->getBatteryPeakConfig( paraOut))
    {
        ui->lineEdit_chargeTime->setText(QString::number(paraOut.chargeTime));
        ui->lineEdit_chargeVolume->setText(QString::number(paraOut.chargeVolume));
        ui->lineEdit_goChargeBatteryLeftLightmode->setText(QString::number(paraOut.goChargeBatteryLeftLightmode));
        ui->lineEdit_warnningBatteryLeftLightmode->setText(QString::number(paraOut.warnningBatteryLeftLightmode));
        ui->lineEdit_shutDownBatteryLeftLightmode->setText(QString::number(paraOut.shutDownBatteryLeftLightmode));


        QMessageBox::information(NULL, "提示", "获取电池参数成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "获取电池参数失败", QMessageBox::Yes );
    }
}

double AgvSetDialog::transformToPi(double angleIn)
{
    int turns;

    if(0<angleIn)
    {
        turns=(angleIn+M_PI) /(2*M_PI);
    }
    else
    {
        turns=(angleIn-M_PI) /(2*M_PI);
    }

    //    angleIn=angleIn-turns*M_PI;//错误
        angleIn=angleIn-turns*M_PI*2;

    if(angleIn>=-M_PI && angleIn<=M_PI)
    {
        return angleIn;
    }
    else if(angleIn<-M_PI)
    {
        return angleIn+2*M_PI;
    }
    else if(angleIn>M_PI)
    {
        return angleIn-2*M_PI;
    }

    return angleIn;
}


void AgvSetDialog::on_pushButton_writeCollisionInfo_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }

    CollisionPara infoOut;

    infoOut.barrierSlowDownDistance_x=ui->lineEdit_barrierSlowDownDistance_x->text().toDouble();
    infoOut.barrierSlowDownDistance_y=ui->lineEdit_barrierSlowDownDistance_y->text().toDouble();
    infoOut.barrierStopDistance_x=ui->lineEdit_barrierStopDistance->text().toDouble();
    infoOut.barrierStopDistance_y=ui->lineEdit_barrierStopDistance_y->text().toDouble();
    infoOut.pieExtendedDistance=ui->lineEdit_pieExtendedDistance->text().toDouble();

    infoOut.stepSafetyRatioList.resize(7);
        infoOut.stepSafetyRatioList[0].velocity=ui->lineEdit_stepVel1->text().toDouble();
        infoOut.stepSafetyRatioList[0].newDistance=ui->lineEdit_stepDistance1->text().toDouble();
        infoOut.stepSafetyRatioList[0].newSlowDownRatio=ui->lineEdit_stepRatio1->text().toDouble();
        infoOut.stepSafetyRatioList[0].newSlowTime=ui->lineEdit_stepRatio_newTime1->text().toDouble();

        infoOut.stepSafetyRatioList[1].velocity=ui->lineEdit_stepVel2->text().toDouble();
        infoOut.stepSafetyRatioList[1].newDistance=ui->lineEdit_stepDistance2->text().toDouble();
        infoOut.stepSafetyRatioList[1].newSlowDownRatio=ui->lineEdit_stepRatio2->text().toDouble();
        infoOut.stepSafetyRatioList[1].newSlowTime=ui->lineEdit_stepRatio_newTime2->text().toDouble();

        infoOut.stepSafetyRatioList[2].velocity=ui->lineEdit_stepVel3->text().toDouble();
        infoOut.stepSafetyRatioList[2].newDistance=ui->lineEdit_stepDistance3->text().toDouble();
        infoOut.stepSafetyRatioList[2].newSlowDownRatio=ui->lineEdit_stepRatio3->text().toDouble();
        infoOut.stepSafetyRatioList[2].newSlowTime=ui->lineEdit_stepRatio_newTime3->text().toDouble();

        infoOut.stepSafetyRatioList[3].velocity=ui->lineEdit_stepVel4->text().toDouble();
        infoOut.stepSafetyRatioList[3].newDistance=ui->lineEdit_stepDistance4->text().toDouble();
        infoOut.stepSafetyRatioList[3].newSlowDownRatio=ui->lineEdit_stepRatio4->text().toDouble();
        infoOut.stepSafetyRatioList[3].newSlowTime=ui->lineEdit_stepRatio_newTime4->text().toDouble();

        infoOut.stepSafetyRatioList[4].velocity=ui->lineEdit_stepVel5->text().toDouble();
        infoOut.stepSafetyRatioList[4].newDistance=ui->lineEdit_stepDistance5->text().toDouble();
        infoOut.stepSafetyRatioList[4].newSlowDownRatio=ui->lineEdit_stepRatio5->text().toDouble();
        infoOut.stepSafetyRatioList[4].newSlowTime=ui->lineEdit_stepRatio_newTime5->text().toDouble();

        infoOut.stepSafetyRatioList[5].velocity=ui->lineEdit_stepVel6->text().toDouble();
        infoOut.stepSafetyRatioList[5].newDistance=ui->lineEdit_stepDistance6->text().toDouble();
        infoOut.stepSafetyRatioList[5].newSlowDownRatio=ui->lineEdit_stepRatio6->text().toDouble();
        infoOut.stepSafetyRatioList[5].newSlowTime=ui->lineEdit_stepRatio_newTime6->text().toDouble();

        infoOut.stepSafetyRatioList[6].velocity=ui->lineEdit_stepVel7->text().toDouble();
        infoOut.stepSafetyRatioList[6].newDistance=ui->lineEdit_stepDistance7->text().toDouble();
        infoOut.stepSafetyRatioList[6].newSlowDownRatio=ui->lineEdit_stepRatio7->text().toDouble();
        infoOut.stepSafetyRatioList[6].newSlowTime=ui->lineEdit_stepRatio_newTime7->text().toDouble();

    int tmpReturn;
    communicateNormal->setSafeCollisionInfo(ui->comboBox_barrierMode->currentIndex(),infoOut,tmpReturn);
    if(1==tmpReturn)
    {
        QMessageBox::information(NULL, "information", "设置成功,即刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置失败！", QMessageBox::Yes );
    }

}

void AgvSetDialog::on_tabWidget_tabBarClicked(int index)
{
    switch (index) {
    case 0:
        readAgvBorderSet();
        break;
    case 1:
        readLaserScanSet();
        break;
    case 2:
        readMotionSet();
        break;
    case 3:
        readBarrierSet();
        break;
    case 4:
        readSheftSet();
        break;
    case 5:
        readAgvPositionCalibrateSet();
        break;
    case 6:
        readLiftSet();
        break;
    case 7:
        readRollerSet();
        break;
    case 8:
        readAmclConfig();
        break;
    case 9:
        readVehicleMotionCalibrate();
        break;
    case 11:
        readReflectConfigInfo();
        readReflectFilterInfo();
        break;
    case 12:
        readBatteryPeakInfo();
        break;

    default:
        break;
    }
}

void AgvSetDialog::on_comboBox_agvType_currentIndexChanged(int index)
{
    QString tmpPicturePath="/agvwork/AgvHmi/baseBag/hmiProject/resources/agvSetView/";
    switch (index) {
    case 0:
        tmpPicturePath+="differAgv.png";
        break;
    case 1:
        tmpPicturePath+="macuumAgv.png";
        break;
    case 2:
        tmpPicturePath+="oneSteerAgv.png";
        break;
    case 3:
        tmpPicturePath+="twoSteerAgv.png";
        break;
    default:
        break;
    }
    ui->frame_carBorder->setStyleSheet( QString("image: url(%1);").arg(tmpPicturePath));
    update();
}

void AgvSetDialog::on_pushButton_setVehicleBorderRect_clicked()
{

    if(false==isAuthorityOk())
    {
        return ;
    }
    int returnFlag;
    BorderRectInfo tmpRect;
    tmpRect.x.push_back(ui->lineEdit_vehicleBorder_x1->text().toDouble());
    tmpRect.x.push_back(ui->lineEdit_vehicleBorder_x2->text().toDouble());
    tmpRect.x.push_back(ui->lineEdit_vehicleBorder_x3->text().toDouble());
    tmpRect.x.push_back(ui->lineEdit_vehicleBorder_x4->text().toDouble());

    tmpRect.y.push_back(ui->lineEdit_vehicleBorder_y1->text().toDouble());
    tmpRect.y.push_back(ui->lineEdit_vehicleBorder_y2->text().toDouble());
    tmpRect.y.push_back(ui->lineEdit_vehicleBorder_y3->text().toDouble());
    tmpRect.y.push_back(ui->lineEdit_vehicleBorder_y4->text().toDouble());

    communicateNormal->setAgvBorderRectInfo(tmpRect,returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "提示", "车边框设置成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "失败", QMessageBox::Yes );
    }

}

void AgvSetDialog::on_pushButton_setKinematicDimension_clicked()
{

    if(false==isAuthorityOk())
    {
        return ;
    }
    VehicleKinematicDimension infoIn;
    int returnFlag;
    infoIn.wa=ui->lineEdit_vehicle_wa->text().toDouble();
    infoIn.wb=ui->lineEdit_vehicle_wb->text().toDouble();
    infoIn.diameter=ui->lineEdit_vehicle_diameter->text().toDouble();

    communicateNormal->setVehicleKinematicDimension(infoIn,returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "提示", "设置成功,重启导航系统生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "提示", "设置失败！", QMessageBox::Yes );
    }

}

void AgvSetDialog::on_pushButton_setLaserScan_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }
    LaserScanParameterHmi infoIn;
    int returnFlag;
    infoIn.minAngle=ui->lineEdit_laserScan_minAngle->text().toDouble();
    infoIn.maxAngle=ui->lineEdit_laserScan_maxAngle->text().toDouble();
    infoIn.position.push_back(ui->lineEdit_laserScan_x->text().toDouble());
    infoIn.position.push_back(ui->lineEdit_laserScan_y->text().toDouble());
    infoIn.position.push_back(ui->lineEdit_laserScan_z->text().toDouble());
    infoIn.position.push_back(ui->lineEdit_laserScan_w->text().toDouble());
    infoIn.position.push_back(ui->lineEdit_laserScan_p->text().toDouble());
    infoIn.position.push_back(ui->lineEdit_laserScan_r->text().toDouble());

    qDebug()<<"LaserScanParameterHmi infoIn.position"<<infoIn.position[0]<<infoIn.position[1]<<infoIn.position[2]
            <<infoIn.position[3]<<infoIn.position[4]<<infoIn.position[5];

    communicateNormal->setLaserScanParameter(0,infoIn,returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "information", "设置成功,重启导航系统生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置失败！", QMessageBox::Yes );
    }

}

void AgvSetDialog::on_pushButton_setVehicleJogControl_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }
    VehicleJogControlParameter infoIn;
    int returnFlag;
    infoIn.maxVel_x=ui->lineEdit_vehicle_jogVel_x->text().toDouble();
    infoIn.maxVel_y=ui->lineEdit_vehicle_jogVel_y->text().toDouble();
    infoIn.maxVel_r=ui->lineEdit_vehicle_jogVel_r->text().toDouble();


    communicateNormal->setVehicleJogControlParameter(infoIn,returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "information", "设置成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置失败！", QMessageBox::Yes );
    }


}

void AgvSetDialog::on_pushButton_setVehicleAutoMove_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }
    VehicleTrajectoryControlParameter infoIn;
    int returnFlag;
    infoIn.maxVel_line=ui->lineEdit_vehicle_traj_maxVelLine->text().toDouble();
    infoIn.maxAcc_line=ui->lineEdit_vehicle_traj_maxAccLine->text().toDouble();
    infoIn.maxVel_rotate=ui->lineEdit_vehicle_traj_maxVelRotate->text().toDouble();
    infoIn.maxAcc_rotate=ui->lineEdit_vehicle_traj_maxAccRotate->text().toDouble();


    communicateNormal->setVehicleTrajectoryControlParameter(infoIn,returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "information", "设置成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置失败！", QMessageBox::Yes );
    }



}

void AgvSetDialog::on_pushButton_setVehicleSheftBorder_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }
    BorderRectInfo infoIn;
    int returnFlag;
    infoIn.x.push_back(ui->lineEdit_vehicleShelf_x1->text().toDouble());
    infoIn.x.push_back(ui->lineEdit_vehicleShelf_x2->text().toDouble());
    infoIn.x.push_back(ui->lineEdit_vehicleShelf_x3->text().toDouble());
    infoIn.x.push_back(ui->lineEdit_vehicleShelf_x4->text().toDouble());

    infoIn.y.push_back(ui->lineEdit_vehicleShelf_y1->text().toDouble());
    infoIn.y.push_back(ui->lineEdit_vehicleShelf_y2->text().toDouble());
    infoIn.y.push_back(ui->lineEdit_vehicleShelf_y3->text().toDouble());
    infoIn.y.push_back(ui->lineEdit_vehicleShelf_y4->text().toDouble());


    communicateNormal->setAgvSheftRectInfo(ui->comboBox_borderId->currentIndex(),infoIn,returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "information", "设置成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置失败！", QMessageBox::Yes );
    }


}

void AgvSetDialog::on_pushButton_setLift_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }
    LiftMechanismConfig infoIn;
    int returnFlag;

    //common
    infoIn.heavyLiftSpeed=ui->lineEdit_liftAxisSpeed->text().toDouble();
    infoIn.isSetSheftRegion=ui->comboBox_liftIsUseSheftBarrier->currentIndex();
    infoIn.liftTimeOut=ui->lineEdit_liftTimeOut->text().toInt();
    infoIn.liftDirectionExchange=ui->comboBox_liftmotorExchangeDirection->currentIndex();

    //block1
    infoIn.blockType=(E_BLOCK_TYPE)ui->comboBox_liftType->currentIndex();
    infoIn.heavyLift_axisId=ui->lineEdit_liftAxisId->text().toInt()-1;
    infoIn.heavyTopSensor_index=ui->lineEdit_liftDi1->text().toInt()-1;
    infoIn.heavyButtomSensor_index=ui->lineEdit_liftDi2->text().toInt()-1;
    infoIn.heavyMiddleSensor_index=ui->lineEdit_liftDiMiddle->text().toInt()-1;
    infoIn.heavyMotorPositive_index=ui->lineEdit_liftDo1->text().toInt()-1;
    infoIn.heavyMotorReverse_index=ui->lineEdit_liftDo2->text().toInt()-1;

    //block2
    infoIn.blockBType=(E_BLOCK_TYPE)ui->comboBox_liftType_2->currentIndex();
    infoIn.heavyLiftB_axisId=ui->lineEdit_liftAxisId_2->text().toInt()-1;
    infoIn.heavyTopSensorB_index=ui->lineEdit_liftDi1_2->text().toInt()-1;
    infoIn.heavyButtomSensorB_index=ui->lineEdit_liftDi2_2->text().toInt()-1;
    infoIn.heavyMiddleSensorB_index=ui->lineEdit_liftDiMiddle_2->text().toInt()-1;
    infoIn.heavyMotorPositiveB_index=ui->lineEdit_liftDo1_2->text().toInt()-1;
    infoIn.heavyMotorReverseB_index=ui->lineEdit_liftDo2_2->text().toInt()-1;

    //watch di
    infoIn.isWatchButtonDi=ui->comboBox_liftIsUseWatchDi->currentIndex();
    infoIn.upButtonDiIndex=ui->lineEdit_liftJogDi1->text().toInt()-1;
    infoIn.downButtonDiIndex=ui->lineEdit_liftJogDi2->text().toInt()-1;
    infoIn.liftManualSpeed=ui->lineEdit_liftJogSpeed->text().toDouble();

    communicateNormal->setLiftMechanismConfig(infoIn,returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "information", "顶升机构设置成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置失败！", QMessageBox::Yes );
    }

}

void AgvSetDialog::on_pushButton_setRoller_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }
    RollerMechanismConfig infoIn;
    int returnFlag;

    //common
    infoIn.rollerMechanicalType=ui->comboBox_rollerType->currentIndex();
    infoIn.blockWaitTime=ui->lineEdit_rollerblockWaitTime->text().toDouble();
    infoIn.leaveDelayTime=ui->lineEdit_rollerdownLoadDelayTime->text().toDouble();
    infoIn.arriveDelayTime=ui->lineEdit_rollerArriveDelayTime->text().toDouble();

    //roller
    infoIn.commonLeftArriveSensor_index=ui->lineEdit_RollerleftArrive->text().toInt()-1;
    infoIn.commonRightArriveSensor_index=ui->lineEdit_RollerRightArrive->text().toInt()-1;
    infoIn.commonLeftLeaveSensor_index=ui->lineEdit_RollerleftLeave->text().toInt()-1;
    infoIn.commonRightLeaveSensor_index=ui->lineEdit_RollerrightLeave->text().toInt()-1;
    infoIn.commonMotorPositiveDo_index=ui->lineEdit_RollercommonDo1->text().toInt()-1;
    infoIn.commonMotorReverseDo_index=ui->lineEdit_RollercommonDo2->text().toInt()-1;
    infoIn.rollerTimeOut=ui->lineEdit_rollerTimeOut->text().toDouble();
    infoIn.rollerMotorType=ui->comboBox_rollermotorControlType->currentIndex();
    infoIn.rollerDirectionExchange=ui->comboBox_rollermotorExchangeDirection->currentIndex();

    //left block1
    infoIn.leftTopSensor_index=ui->lineEdit_RollerleftBlockDi1->text().toInt()-1;
    infoIn.leftButtomSensor_index=ui->lineEdit_RollerleftBlockDi2->text().toInt()-1; 
    infoIn.leftBlockDo1_index=ui->lineEdit_RollerleftBlockDo1->text().toInt()-1;
    infoIn.leftBlockDo2_index=ui->lineEdit_RollerleftBlockDo2->text().toInt()-1;
    infoIn.leftBlockType=(E_BLOCK_TYPE)ui->comboBox_RollerLeftblockType->currentIndex();

    //right block1
    infoIn.rightTopSensor_index=ui->lineEdit_RollerRightBlockDi1->text().toInt()-1;
    infoIn.rightButtomSensor_index=ui->lineEdit_RollerRightBlockDi2->text().toInt()-1;
    infoIn.rightBlockDo1_index=ui->lineEdit_RollerRightBlockDo1->text().toInt()-1;
    infoIn.rightBlockDo2_index=ui->lineEdit_RollerRightBlockDo2->text().toInt()-1;
    infoIn.rightBlockType=(E_BLOCK_TYPE)ui->comboBox_RollerRightblockType->currentIndex();

    //left block2
    infoIn.leftTopSensorB_index=ui->lineEdit_RollerleftBlockDi1_2->text().toInt()-1;
    infoIn.leftButtomSensorB_index=ui->lineEdit_RollerleftBlockDi2_2->text().toInt()-1;
    infoIn.leftBlockDo1B_index=ui->lineEdit_RollerleftBlockDo1_2->text().toInt()-1;
    infoIn.leftBlockDo2B_index=ui->lineEdit_RollerleftBlockDo2_2->text().toInt()-1;
    infoIn.leftBlockBType=(E_BLOCK_TYPE)ui->comboBox_RollerLeftblockType_2->currentIndex();

    //right block2
    infoIn.rightTopSensorB_index=ui->lineEdit_RollerRightBlockDi1_2->text().toInt()-1;
    infoIn.rightButtomSensorB_index=ui->lineEdit_RollerRightBlockDi2_2->text().toInt()-1;
    infoIn.rightBlockDo1B_index=ui->lineEdit_RollerRightBlockDo1_2->text().toInt()-1;
    infoIn.rightBlockDo2B_index=ui->lineEdit_RollerRightBlockDo2_2->text().toInt()-1;
    infoIn.rightBlockBType=(E_BLOCK_TYPE)ui->comboBox_RollerRightblockType_2->currentIndex();

    communicateNormal->setRollerMechanismConfig(infoIn,returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "information", "滚筒机构设置成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置失败！", QMessageBox::Yes );
    }

}

void AgvSetDialog::on_comboBox_borderId_currentIndexChanged(int index)
{
    on_tabWidget_tabBarClicked(ui->tabWidget->currentIndex());
}

void AgvSetDialog::on_comboBox_barrierMode_currentIndexChanged(int index)
{
    readBarrierSet();
}

void AgvSetDialog::on_pushButton_setAmclConfig_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }
    struct AmclDebugPara infoIn;
    int returnFlag;
    infoIn.calculateTimesForLaser=ui->lineEdit_calculateTimesForLaser->text().toInt();
    infoIn.laser_max_beams=ui->lineEdit_laser_max_beams->text().toInt();
    infoIn.min_particles=ui->lineEdit_min_particles->text().toInt();
    infoIn.max_particles=ui->lineEdit_max_particles->text().toInt();
    infoIn.update_min_d=ui->lineEdit_update_min_d->text().toDouble();
    infoIn.update_min_a=ui->lineEdit_update_min_a->text().toDouble();
    infoIn.odom_alpha1=ui->lineEdit_odom_alpha1->text().toDouble();
    infoIn.odom_alpha2=ui->lineEdit_odom_alpha2->text().toDouble();
    infoIn.odom_alpha3=ui->lineEdit_odom_alpha3->text().toDouble();
    infoIn.odom_alpha4=ui->lineEdit_odom_alpha4->text().toDouble();
    infoIn.odom_alpha5=ui->lineEdit_odom_alpha5->text().toDouble();
    infoIn.badMatchScore=ui->lineEdit_badMatchScore->text().toDouble();
    infoIn.goodMatchScore=ui->lineEdit_goodMatchScore->text().toDouble();
    infoIn.newOdom_alpha_badMatchScore=ui->lineEdit_newOdom_alpha_badMatchScore->text().toDouble();
    infoIn.recovery_alpha_slow=ui->lineEdit_recovery_alpha_slow->text().toDouble();
    infoIn.recovery_alpha_fast=ui->lineEdit_recovery_alpha_fast->text().toDouble();
    infoIn.resample_interval=ui->lineEdit_resample_interval->text().toInt();

    infoIn.odomOffsetFilterCount=ui->lineEdit_odomOffsetFilterCount_amcl->text().toInt();
    infoIn.isCorrectByReflect=ui->lineEdit_isCorrectByReflect->text().toInt();
    infoIn.correctFilterCount=ui->lineEdit_correctFilterCount_amcl->text().toInt();
    infoIn.correctAllowMaxDistanceOffset=ui->lineEdit_correctAllowMaxDistanceOffset_amcl->text().toDouble();
    infoIn.correctAllowMaxAngleOffset=ui->lineEdit_correctAllowMaxAngleOffset_amcl->text().toDouble();
    infoIn.qualifyReflectMinCertaintyScore=ui->lineEdit_qualifyReflectMinCertaintyScore->text().toDouble();

    communicateNormal->setAmclPara( infoIn,returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "information", "amcl设置成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置失败！", QMessageBox::Yes );
    }
}

void AgvSetDialog::on_pushButton_recordStartPosition_clicked()
{
    OdemeterData odemeterDataReturn;
    communicateNormal->getOdometer(1,odemeterDataReturn);
    ui->lineEdit_originPosex->setText(QString::number(odemeterDataReturn.pos.x));
    ui->lineEdit_originPosey->setText(QString::number(odemeterDataReturn.pos.y));
    ui->lineEdit_originPoser->setText(QString::number(180.0*odemeterDataReturn.pos.rotate/M_PI));

}

void AgvSetDialog::on_pushButton_recordStopPosition_clicked()
{
    OdemeterData odemeterDataReturn;
    communicateNormal->getOdometer(1,odemeterDataReturn);
    ui->lineEdit_stopPoseX->setText(QString::number(odemeterDataReturn.pos.x));
    ui->lineEdit_stopPoseY->setText(QString::number(odemeterDataReturn.pos.y));
    ui->lineEdit_stopPoseR->setText(QString::number(180.0*odemeterDataReturn.pos.rotate/M_PI));
}

void AgvSetDialog::on_pushButton_setVehicleMotionCalibrateLength_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }
    double idealMovedLength,  actualMovedLength;
    int returnFlag;
    actualMovedLength=ui->lineEdit_idealMovedLength->text().toDouble();
    double x1=ui->lineEdit_originPosex->text().toDouble();
    double y1=ui->lineEdit_originPosey->text().toDouble();
    double x2=ui->lineEdit_stopPoseX->text().toDouble();
    double y2=ui->lineEdit_stopPoseY->text().toDouble();
    idealMovedLength=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    qDebug()<<"setVehicleMotionCalibrateLength idealMovedLength"<<idealMovedLength
           <<"actualMovedLength"<<actualMovedLength;
    ui->lineEdit_mathDistance->setText(QString::number(idealMovedLength,'f',3));
    communicateNormal->setCalibrateWheelDiameter( idealMovedLength,actualMovedLength,returnFlag);
    if(1==returnFlag)
    {
        readVehicleMotionCalibrate();
        QMessageBox::information(NULL, "information", "设置成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置失败！", QMessageBox::Yes );
    }
}

void AgvSetDialog::on_pushButton_recordStartPosition_2_clicked()
{
    OdemeterData odemeterDataReturn;
    communicateNormal->getOdometer(1,odemeterDataReturn);
    ui->lineEdit_originPosex_2->setText(QString::number(odemeterDataReturn.pos.x));
    ui->lineEdit_originPosey_2->setText(QString::number(odemeterDataReturn.pos.y));
    ui->lineEdit_originPoser_2->setText(QString::number(180.0*odemeterDataReturn.pos.rotate/M_PI));
}

void AgvSetDialog::on_pushButton_recordStopPosition_2_clicked()
{
    OdemeterData odemeterDataReturn;
    communicateNormal->getOdometer(1,odemeterDataReturn);
    ui->lineEdit_stopPoseX_2->setText(QString::number(odemeterDataReturn.pos.x));
    ui->lineEdit_stopPoseY_2->setText(QString::number(odemeterDataReturn.pos.y));
    ui->lineEdit_stopPoseR_2->setText(QString::number(180.0*odemeterDataReturn.pos.rotate/M_PI));
}

void AgvSetDialog::on_pushButton_setVehicleMotionCalibrateAngle_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }
    double idealMovedAngle,  actualMovedAngle;
    int returnFlag;
    actualMovedAngle=ui->lineEdit_idealMovedLength_2->text().toDouble();
    double startAngle=ui->lineEdit_originPoser_2->text().toDouble();
    double endAngle=ui->lineEdit_stopPoseR_2->text().toDouble();
    startAngle=transformToPi(M_PI*startAngle/180.0);
    endAngle=transformToPi(M_PI*endAngle/180.0);
    idealMovedAngle=2*M_PI+endAngle-startAngle;
    idealMovedAngle=180.0*idealMovedAngle/M_PI;
    qDebug()<<"setVehicleMotionCalibrateAngle idealMovedAngle"<<idealMovedAngle
           <<"actualMovedAngle"<<360;
    ui->lineEdit_mathAngle->setText(QString::number(idealMovedAngle,'f',3));

    communicateNormal->setCalibrateWheelDistance(idealMovedAngle,360.0,returnFlag);
    if(1==returnFlag)
    {
        readVehicleMotionCalibrate();
        QMessageBox::information(NULL, "information", "设置成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置失败！", QMessageBox::Yes );
    }
}

void AgvSetDialog::on_pushButton_setIpAddress_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }

    int returnFlag;
    QString netName=ui->comboBox_ipNet->currentText();
    QString netIp=ui->lineEdit_ipAddress->text();

    communicateNormal->setEthernetIpAddress(netName.toStdString(),netIp.toStdString(),returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "information", "设置ip成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置ip失败！", QMessageBox::Yes );
    }
}

void AgvSetDialog::on_pushButton_setReflectLaserFilterPara_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }

    int returnFlag;
    LaserFilterParameter tmpFilter;
    int index=ui->comboBox_reflectFilterIndex->currentIndex();
    tmpFilter.minumIntensity=ui->lineEdit_minumIntensity_filter->text().toDouble();
    tmpFilter.minLaserRange=ui->lineEdit_minLaserRange_filter->text().toDouble();
    tmpFilter.maxLaserRange=ui->lineEdit_maxLaserRange_filter->text().toDouble();
    tmpFilter.minAngle=ui->lineEdit_minAngle_filter->text().toDouble();
    tmpFilter.maxAngle=ui->lineEdit_maxAngle_filter->text().toDouble();
    tmpFilter.region_front=ui->lineEdit_region_front_filter->text().toDouble();
    tmpFilter.region_back=ui->lineEdit_region_back_filter->text().toDouble();
    tmpFilter.region_left=ui->lineEdit_region_left_filter->text().toDouble();
    tmpFilter.region_right=ui->lineEdit_region_right_filter->text().toDouble();

    communicateNormal->setReflectLaserFilterParameter(index,tmpFilter,returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "information", "设置反光过滤参数成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置反光过滤参数失败！", QMessageBox::Yes );
    }
}

void AgvSetDialog::on_pushButton_setReflectCalculateConfig_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }

    int returnFlag;

    ReflectCommonDetectPara tmpPara;
    tmpPara.allowMinMarkDistance=ui->lineEdit_allowMinMarkDistance->text().toDouble();


    tmpPara.minimumReferencePointCount=ui->lineEdit_minimumReferencePointCount->text().toDouble();
    tmpPara.maxmumReferencePointCount=ui->lineEdit_maxmumReferencePointCount->text().toDouble();
    tmpPara.maxMatchLineDistanceOffset=ui->lineEdit_maxMatchLineDistanceOffset->text().toDouble();
    tmpPara.initial_AgvPositionOffset=ui->lineEdit_initial_AgvPositionOffset->text().toDouble();
    tmpPara.initial_AgvAngleOffset=ui->lineEdit_initial_AgvAngleOffset->text().toDouble();
    tmpPara.mached_AgvPositionOffset=ui->lineEdit_mached_AgvPositionOffset->text().toDouble();
    tmpPara.mached_AgvAngleOffset=ui->lineEdit_mached_AgvAngleOffset->text().toDouble();
    tmpPara.odomErrorRatio_position=ui->lineEdit_odomErrorRatio_position->text().toDouble();
    tmpPara.odomErrorRatio_angle=ui->lineEdit_odomErrorRatio_angle->text().toDouble();
    tmpPara.laserIntensityLoseRatio=ui->lineEdit_laserIntensityLoseRatio->text().toDouble();
    tmpPara.matchColumnMarkDiameterTolorenceRatio=ui->lineEdit_matchColumnMarkDiameterTolorenceRatio->text().toDouble();
    tmpPara.matchPlaneMarkMinWidth=ui->lineEdit_matchPlaneMarkMinWidth->text().toDouble();
    tmpPara.matchPlaneMarkMaxWidth=ui->lineEdit_matchPlaneMarkMaxWidth->text().toDouble();
    tmpPara.odomOffsetFilterCount=ui->lineEdit_odomOffsetFilterCount->text().toDouble();
    tmpPara.minCorssAngle=ui->lineEdit_minCorssAngle->text().toDouble();
    tmpPara.idealRadius=ui->lineEdit_idealRadius->text().toDouble();
    tmpPara.idealMatchNum=ui->lineEdit_idealMatchNum->text().toDouble();

    tmpPara.isCorrectByAmcl=ui->lineEdit_isCorrectByAmcl->text().toDouble();
    tmpPara.qualifyAmclMinCertaintyScore=ui->lineEdit_qualifyAmclMinCertaintyScore->text().toDouble();
    tmpPara.correctFilterCount=ui->lineEdit_correctFilterCount_reflect->text().toDouble();
    tmpPara.correctAllowMaxDistanceOffset=ui->lineEdit_correctAllowMaxDistanceOffset_reflect->text().toDouble();
    tmpPara.correctAllowMaxAngleOffset=ui->lineEdit_correctAllowMaxAngleOffset_reflect->text().toDouble();
    tmpPara.correctOdomErrorDistanceThreshold=ui->lineEdit_correctOdomErrorDistanceThreshold->text().toDouble();
    tmpPara.correctOdomErrorAngleThreshold=ui->lineEdit_correctOdomErrorAngleThreshold->text().toDouble();


    communicateNormal->setReflectCalculateCommonParameter(tmpPara,returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "information", "设置反光计算参数成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置反光计算参数失败！", QMessageBox::Yes );
    }
}

void AgvSetDialog::on_pushButton_getReflectLaserFilterPara_clicked()
{
    readReflectFilterInfo();
}

void AgvSetDialog::on_pushButton_setBatteryPeakConfig_clicked()
{
    if(false==isAuthorityOk())
    {
        return ;
    }

    int returnFlag;

    BatteryPeakConfig configIn;
    configIn.chargeTime=ui->lineEdit_chargeTime->text().toDouble();
    configIn.chargeVolume=ui->lineEdit_chargeVolume->text().toDouble();
    configIn.goChargeBatteryLeftLightmode=ui->lineEdit_goChargeBatteryLeftLightmode->text().toDouble();
    configIn.shutDownBatteryLeftLightmode=ui->lineEdit_shutDownBatteryLeftLightmode->text().toDouble();
    configIn.warnningBatteryLeftLightmode=ui->lineEdit_warnningBatteryLeftLightmode->text().toDouble();



    communicateNormal->setBatteryPeakConfig( configIn,returnFlag);
    if(1==returnFlag)
    {
        QMessageBox::information(NULL, "information", "设置电池参数成功,立刻生效！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "设置电池参数失败！", QMessageBox::Yes );
    }
}
